<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

echo '<p>';
	echo "<a href='../'>&lt;&lt; Back to Main Portal</a><br />";
echo '</p>';
echo "<h1>Semesters Portal</h1>";
echo '<p>';
//creates link/button for add semester
echo "<a href='add.php'>Add Semester OR Season</a>";
echo '</p>';

//counting variable
$i = 0;

$result=mysql_query("SELECT * 
						FROM seasons 
						JOIN semesters
						ON semesters.season_id=seasons.id
						ORDER BY semesters.year DESC, seasons.id DESC");

//determine dynamically number of rows read from table
$num_rows=mysql_numrows($result);

$insert_point = $num_rows + 1;

if ($num_rows > 0)
{

	//start table
	echo "<table class=\"postSchedule\">";
		
		//create table row with column ID's
		echo "<tr>";
			echo "<td style='text-align: center' width='150'><b>Session Number</b></td>";
			echo "<td style='text-align: center' width='130'><b>Year</b></td>";
			echo "<td style='text-align: center' width='130'><b>Season</b></td>";
			echo "<td style='text-align: center' width='130'><b>Start Date</b></td>";
			echo "<td style='text-align: center' width='130'><b>End Date</b></td>";
			echo "<td></td>";
			echo "<td></td>";
		echo "</tr>";

	//loop to walk through and print to screen all entries in semesters table
	$row_count=0;
	while ($i < $num_rows) 
	{
		$row_count++;
		$season_id=mysql_result($result,$i,"seasons.id");
		$semester_id=mysql_result($result,$i,"semesters.id");
		
		$session_number=mysql_result($result,$i,"semesters.session_number");
		$year=mysql_result($result,$i,"semesters.year");		
		$season=mysql_result($result,$i,"seasons.season");
		
		$start_date=mysql_result($result,$i,"semesters.start_date");
		$end_date=mysql_result($result,$i,"semesters.end_date");
		
		echo "<tr";
		if (($row_count%2) != 0) echo " class=\"zebra_stripe\"";
		echo ">";
			echo "<td style='text-align: center' width='130'>$session_number</td>";
			echo "<td style='text-align: center' width='130'>$year</td>";
			echo "<td style='text-align: center' width='130'>$season</td>";
			echo "<td style='text-align: center' width='130'>$start_date</td>";
			echo "<td style='text-align: center' width='130'>$end_date</td>";
			
			echo "<td>";		//cell containing form for edit link/button
				echo "<a href='edit.php?id=$semester_id'>Edit</a>";
			echo "</td>";
			
			echo "<td>";		//cell containing form for delete link/button
				echo "<a href='delete.php?id=$semester_id'>Delete</a>";
			echo "</td>";
		echo "</tr>";
			
		//increment counting variable
		$i++;
	}

	//end table tag
	echo "</table>";


}
else
{
	echo "<p><b>NO SEMESTERS CURRENTLY ASSIGNED</b></p>";
}




?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>